import glob
import os
import sys

# Establish UTF-8 encoding for Python 2.
if sys.version_info < (3, 0):
	reload(sys)
	sys.setdefaultencoding('utf-8')

# Create build environment.
env = Environment(ENV = {'PATH' : os.environ['PATH']})

# Determine compiler and linker flags for SDL.
env.ParseConfig('sdl2-config --cflags')
env.ParseConfig('sdl2-config --libs')

# Gather a list of source files.
SOURCES = glob.glob('*.cpp')

SOURCES += glob.glob('../../Analyser/Dynamic/*.cpp')
SOURCES += glob.glob('../../Analyser/Dynamic/MultiMachine/*.cpp')
SOURCES += glob.glob('../../Analyser/Dynamic/MultiMachine/Implementation/*.cpp')

SOURCES += glob.glob('../../Analyser/Static/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Acorn/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Amiga/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/AmstradCPC/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/AppleII/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/AppleIIgs/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Atari2600/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/AtariST/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Coleco/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Commodore/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Disassembler/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/DiskII/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Enterprise/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/FAT12/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Macintosh/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/MSX/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Oric/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/PCCompatible/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/Sega/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/ZX8081/*.cpp')
SOURCES += glob.glob('../../Analyser/Static/ZXSpectrum/*.cpp')

SOURCES += glob.glob('../../Components/1770/*.cpp')
SOURCES += glob.glob('../../Components/5380/*.cpp')
SOURCES += glob.glob('../../Components/6522/Implementation/*.cpp')
SOURCES += glob.glob('../../Components/6560/*.cpp')
SOURCES += glob.glob('../../Components/6850/*.cpp')
SOURCES += glob.glob('../../Components/68901/*.cpp')
SOURCES += glob.glob('../../Components/8272/*.cpp')
SOURCES += glob.glob('../../Components/8530/*.cpp')
SOURCES += glob.glob('../../Components/9918/*.cpp')
SOURCES += glob.glob('../../Components/9918/Implementation/*.cpp')
SOURCES += glob.glob('../../Components/AudioToggle/*.cpp')
SOURCES += glob.glob('../../Components/AY38910/*.cpp')
SOURCES += glob.glob('../../Components/DiskII/*.cpp')
SOURCES += glob.glob('../../Components/I2C/*.cpp')
SOURCES += glob.glob('../../Components/KonamiSCC/*.cpp')
SOURCES += glob.glob('../../Components/OPx/*.cpp')
SOURCES += glob.glob('../../Components/RP5C01/*.cpp')
SOURCES += glob.glob('../../Components/SAA5050/*.cpp')
SOURCES += glob.glob('../../Components/SID/*.cpp')
SOURCES += glob.glob('../../Components/SN76489/*.cpp')
SOURCES += glob.glob('../../Components/Serial/*.cpp')
SOURCES += glob.glob('../../Components/uPD7002/*.cpp')

SOURCES += glob.glob('../../Configurable/*.cpp')

SOURCES += glob.glob('../../Inputs/*.cpp')

SOURCES += glob.glob('../../InstructionSets/M50740/*.cpp')
SOURCES += glob.glob('../../InstructionSets/M68k/*.cpp')
SOURCES += glob.glob('../../InstructionSets/PowerPC/*.cpp')
SOURCES += glob.glob('../../InstructionSets/x86/*.cpp')

SOURCES += glob.glob('../../Machines/*.cpp')
SOURCES += glob.glob('../../Machines/Acorn/Archimedes/*.cpp')
SOURCES += glob.glob('../../Machines/Acorn/BBCMicro/*.cpp')
SOURCES += glob.glob('../../Machines/Acorn/Electron/*.cpp')
SOURCES += glob.glob('../../Machines/Amiga/*.cpp')
SOURCES += glob.glob('../../Machines/AmstradCPC/*.cpp')
SOURCES += glob.glob('../../Machines/Apple/ADB/*.cpp')
SOURCES += glob.glob('../../Machines/Apple/AppleII/*.cpp')
SOURCES += glob.glob('../../Machines/Apple/AppleIIgs/*.cpp')
SOURCES += glob.glob('../../Machines/Apple/Macintosh/*.cpp')
SOURCES += glob.glob('../../Machines/Atari/2600/*.cpp')
SOURCES += glob.glob('../../Machines/Atari/ST/*.cpp')
SOURCES += glob.glob('../../Machines/ColecoVision/*.cpp')
SOURCES += glob.glob('../../Machines/Commodore/*.cpp')
SOURCES += glob.glob('../../Machines/Commodore/1540/Implementation/*.cpp')
SOURCES += glob.glob('../../Machines/Commodore/Vic-20/*.cpp')
SOURCES += glob.glob('../../Machines/Commodore/Plus4/*.cpp')
SOURCES += glob.glob('../../Machines/Enterprise/*.cpp')
SOURCES += glob.glob('../../Machines/MasterSystem/*.cpp')
SOURCES += glob.glob('../../Machines/MSX/*.cpp')
SOURCES += glob.glob('../../Machines/Oric/*.cpp')
SOURCES += glob.glob('../../Machines/PCCompatible/*.cpp')
SOURCES += glob.glob('../../Machines/Utility/*.cpp')
SOURCES += glob.glob('../../Machines/Sinclair/Keyboard/*.cpp')
SOURCES += glob.glob('../../Machines/Sinclair/ZX8081/*.cpp')
SOURCES += glob.glob('../../Machines/Sinclair/ZXSpectrum/*.cpp')

SOURCES += glob.glob('../../Outputs/*.cpp')
SOURCES += glob.glob('../../Outputs/CRT/*.cpp')
SOURCES += glob.glob('../../Outputs/ScanTargets/*.cpp')
SOURCES += glob.glob('../../Outputs/OpenGL/*.cpp')
SOURCES += glob.glob('../../Outputs/OpenGL/Primitives/*.cpp')

SOURCES += glob.glob('../../Processors/6502/Implementation/*.cpp')
SOURCES += glob.glob('../../Processors/6502/State/*.cpp')
SOURCES += glob.glob('../../Processors/65816/Implementation/*.cpp')
SOURCES += glob.glob('../../Processors/Z80/Implementation/*.cpp')
SOURCES += glob.glob('../../Processors/Z80/State/*.cpp')

SOURCES += glob.glob('../../Reflection/*.cpp')

SOURCES += glob.glob('../../SignalProcessing/*.cpp')

SOURCES += glob.glob('../../Storage/*.cpp')
SOURCES += glob.glob('../../Storage/Cartridge/*.cpp')
SOURCES += glob.glob('../../Storage/Cartridge/Encodings/*.cpp')
SOURCES += glob.glob('../../Storage/Cartridge/Formats/*.cpp')
SOURCES += glob.glob('../../Storage/Data/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Controller/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/DiskImage/Formats/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/DiskImage/Formats/Utility/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/DPLL/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Encodings/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Encodings/AppleGCR/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Encodings/MFM/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Parsers/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Track/*.cpp')
SOURCES += glob.glob('../../Storage/Disk/Data/*.cpp')
SOURCES += glob.glob('../../Storage/FileBundle/*.cpp')
SOURCES += glob.glob('../../Storage/MassStorage/*.cpp')
SOURCES += glob.glob('../../Storage/MassStorage/Encodings/*.cpp')
SOURCES += glob.glob('../../Storage/MassStorage/Formats/*.cpp')
SOURCES += glob.glob('../../Storage/MassStorage/SCSI/*.cpp')
SOURCES += glob.glob('../../Storage/State/*.cpp')
SOURCES += glob.glob('../../Storage/Tape/*.cpp')
SOURCES += glob.glob('../../Storage/Tape/Formats/*.cpp')
SOURCES += glob.glob('../../Storage/Tape/Parsers/*.cpp')

# Add additional compiler flags; c++2a is insurance in case c++20 isn't fully implemented.
env.Append(CCFLAGS = ['--std=c++20', '--std=c++2a', '-Wall', '-O2', '-DNDEBUG', '-I../..'])

# Add additional libraries to link against.
env.Append(LIBS = ['libz', 'pthread'])

# Add additional platform-specific compiler flags, libraries, and frameworks.
if env['PLATFORM'] == 'darwin':
	env.Append(CCFLAGS = ['-DGL_SILENCE_DEPRECATION', '-DIGNORE_APPLE'])
	env.Append(FRAMEWORKS = ['Accelerate', 'OpenGL'])
else:
	env.Append(LIBS = ['GL'])

# Build target.
env.Program(target = 'clksignal', source = SOURCES)
